home *** CD-ROM | disk | FTP | other *** search
/ Apple Technical Information Source 1992 September / Apple Tech I.S. 3.0 (Sept-1992).toast / Third Party SW Updates / AppMaker⁄MacApp for MacApp 3 / UAMLibraryM.cp < prev    next >
Encoding:
Text File  |  1991-06-04  |  21.6 KB  |  859 lines  |  [TEXT/MPS ]

  1. // © 1991, Bowers Development Corp.
  2. // UAMLibraryM.cp
  3.  
  4. #include "UAMLibraryM.h"
  5. #ifndef __TYPES__
  6.     #include <Types.h>
  7. #endif
  8. #ifndef __QUICKDRAW__
  9.     #include <Quickdraw.h>
  10. #endif
  11. #ifndef __RESOURCES__
  12.     #include <Resources.h>
  13. #endif
  14.  
  15. const long kStdGrayLine            = 'Line';
  16. const long kStdPalette            = 'Palt';
  17. const long kStdPictButton        = 'pBut';
  18. const long kStdPictCheckBox        = 'pChk';
  19. const long kStdPictRadio        = 'pRad';
  20. const long kStdMultiPict        = 'pMul';
  21. const long kStdSlider            = 'Sldr';
  22. const long kStdCustom            = 'Cust';
  23.  
  24.  
  25. #pragma segment AMControlRes
  26. /*----------*/
  27. pascal void ActionProcForTSlider     (ControlHandle        aCMgrControl,
  28.                                       short                partCode)
  29. {
  30.     TSlider        *aSlider;
  31.  
  32.     aSlider = (TSlider *) GetCRefCon (aCMgrControl);
  33.     FailNIL (aSlider);
  34.  
  35.     aSlider->ActionProc (partCode);
  36. } /* ActionProcForTSlider */
  37.  
  38.  
  39. //-------------------------------------------------------
  40. // TGrayLine (TView)        Gray line
  41. //-------------------------------------------------------
  42.  
  43. #pragma segment ARes
  44. /*----------*/
  45. pascal void TGrayLine::Draw        (const VRect&        area)
  46. {    
  47.     PenState        savePen;
  48.  
  49.     GetPenState (savePen);
  50.     PenNormal ();
  51.     PenPat (qd.gray);
  52. //????? the following is wrong. it should draw from view's coordinates not from rect's
  53.     MoveTo (area.left, area.top);
  54.     LineTo (area.right - 1, area.bottom - 1);
  55.  
  56.     SetPenState (savePen);
  57. } /* Draw */
  58.  
  59. //-------------------------------------------------------
  60. // TPalette (TCtlMgr)        Palette
  61. //-------------------------------------------------------
  62.  
  63. #pragma segment AOpen
  64. /*----------*/
  65. pascal void TPalette::IPalette      (TView                *itsSuperView,
  66.                                      const VPoint&        itsLocation, 
  67.                                      const VPoint&        itsSize,
  68.                                      SizeDeterminer        itsHSizeDet, 
  69.                                      SizeDeterminer        itsVSizeDet,
  70.                                      short                itsPictureID,
  71.                                      short                itsNumberAcross,
  72.                                      short                itsNumberDown,
  73.                                      short                itsFrameSize)    
  74. {
  75.     Str255        itsLabel;
  76.  
  77.     itsLabel [0] = 4;
  78.     itsLabel [1] = (Byte) (itsPictureID >> 8);
  79.     itsLabel [2] = (Byte) (itsPictureID & 0x00FF);
  80.     itsLabel [3] = (Byte) itsNumberAcross;
  81.     itsLabel [4] = (Byte) itsNumberDown;
  82.  
  83.     ICtlMgr (itsSuperView, itsLocation, itsSize, 
  84.                 itsHSizeDet, itsVSizeDet, itsLabel, 
  85.                 1, 1, (itsNumberAcross * itsNumberDown), 
  86.                 (kPaletteProcID + itsFrameSize));
  87.     fDefChoice = mPaletteHit;
  88. } /* IPalette */
  89.  
  90. #pragma segment AInit
  91. /*----------*/
  92. pascal void TPalette::IRes         (TDocument            *itsDocument,
  93.                                  TView                *itsSuperView,
  94.                                  Ptr&                itsParams)                 
  95. {
  96.     VRect            itsArea;
  97.     Str255            itsLabel;
  98.     PaletteTPtr        ptPtr;
  99.  
  100.     inherited::IRes (itsDocument, itsSuperView, itsParams);
  101.  
  102.     fDefChoice = mPaletteHit;
  103.     ptPtr = (PaletteTPtr) itsParams;
  104.     itsLabel [0] = 4;
  105.     itsLabel [1] = (Byte) (ptPtr->itsPictureID >> 8);
  106.     itsLabel [2] = (Byte) (ptPtr->itsPictureID & 0x00FF);
  107.     itsLabel [3] = (Byte) ptPtr->itsNumberAcross;
  108.     itsLabel [4] = (Byte) ptPtr->itsNumberDown;
  109.     ControlArea (itsArea);
  110.     CreateCMgrControl (itsArea, itsLabel, 1, 1, 
  111.                             (ptPtr->itsNumberDown * ptPtr->itsNumberAcross), 
  112.                             (kPaletteProcID + ptPtr->itsFrameSize));
  113.     
  114.     OffsetPtr (itsParams, sizeof (PaletteTemplate));
  115. } /* IRes */
  116.  
  117. #pragma segment WriteRes
  118. /*----------*/
  119. pascal void TPalette::WRes        (ViewRsrcHandle        theResource,
  120.                                  Ptr&                itsParams) 
  121. {
  122.     Str255            theLabel;
  123.     PaletteTPtr        ptPtr;
  124.  
  125.     inherited::WRes (theResource, itsParams);    
  126.     
  127.     GetText (theLabel);
  128.     ptPtr = (PaletteTPtr) (ExpandPtr ((Handle)theResource, itsParams,
  129.                                 sizeof (PaletteTemplate)) );
  130.     ptPtr->itsPictureID = (short) ((theLabel [1] << 8) + theLabel [2]);
  131.     ptPtr->itsNumberAcross = (short) theLabel [3];
  132.     ptPtr->itsNumberDown = (short) theLabel [4];
  133.     ptPtr->itsFrameSize = GetCVariant (fCMgrControl);
  134.  
  135. } /* WRes */
  136.  
  137. #pragma segment WriteRes
  138. /*----------*/
  139. pascal void TPalette::WriteRes          (ViewRsrcHandle        theResource,
  140.                                      Ptr&                itsParams)
  141. {
  142.     gWResSignature = kStdPalette; 
  143.     gWResType = "TPalette";
  144.     WRes (theResource, itsParams);
  145. } /* WriteRes */
  146.  
  147. #pragma segment AFields
  148. /*----------*/
  149. pascal void TPalette::Fields    (TObject*            obj)
  150. {
  151.     obj->DoToField ("TPalette", NULL, bClass);
  152.     inherited::Fields (obj);
  153. } /* Fields */
  154.  
  155. //-------------------------------------------------------
  156. // TPictButton (TCtlMgr)        Picture button
  157. //-------------------------------------------------------
  158.  
  159. #pragma segment AOpen
  160. /*----------*/
  161. pascal void TPictButton::IPictButton    (TView                *itsSuperView,
  162.                                          const VPoint&        itsLocation, 
  163.                                          const VPoint&        itsSize,
  164.                                          SizeDeterminer        itsHSizeDet, 
  165.                                          SizeDeterminer        itsVSizeDet,
  166.                                          const Str255&        itsPicts)    
  167. {
  168.     ICtlMgr (itsSuperView, itsLocation, itsSize, 
  169.                 itsHSizeDet, itsVSizeDet, itsPicts, 
  170.                 0, 0, 1, kPictButtonProcID);
  171.     fDefChoice = mButtonHit;
  172. } /* IPictButton */
  173.  
  174. #pragma segment AInit
  175. /*----------*/
  176. pascal void TPictButton::IRes         (TDocument            *itsDocument,
  177.                                      TView                *itsSuperView,
  178.                                      Ptr&                itsParams)
  179. {
  180.     VRect                itsArea;
  181.     PictControlTPtr        ptPtr;
  182.  
  183.     inherited::IRes (itsDocument, itsSuperView, itsParams);
  184.  
  185.     fDefChoice = mButtonHit;
  186.     ptPtr = (PictControlTPtr) itsParams;
  187.     ControlArea (itsArea);
  188.     CreateCMgrControl (itsArea, ptPtr->itsPictureIDs, 
  189.                             0, 0, 1, kPictButtonProcID);
  190.     
  191.     OffsetPtrWStr (itsParams, sizeof (PictControlTemplate));
  192. } /* IRes */
  193.  
  194. #pragma segment WriteRes
  195. /*----------*/
  196. pascal void TPictButton::WRes        (ViewRsrcHandle        theResource,
  197.                                      Ptr&                itsParams) 
  198.     Str255                theLabel;
  199.     PictControlTPtr        ptPtr;
  200.  
  201.     inherited::WRes (theResource, itsParams);    
  202.     
  203.     GetText (theLabel);
  204.     ptPtr = (PictControlTPtr) (ExpandPtrWStr ((Handle)theResource, itsParams, 
  205.                                     sizeof (PictControlTemplate), theLabel [0]));
  206.     CopyStr255 (theLabel, PRStr (ptPtr->itsPictureIDs));
  207. } /* WRes */
  208.  
  209. #pragma segment WriteRes
  210. /*----------*/
  211. pascal void TPictButton::WriteRes    (ViewRsrcHandle        theResource,
  212.                                      Ptr&                itsParams)
  213. {
  214.     gWResSignature = kStdPictButton; 
  215.     gWResType = "TPictButton";
  216.     WRes (theResource, itsParams);
  217. } /* WriteRes */
  218.  
  219. #pragma segment AFields
  220. /*----------*/
  221. pascal void TPictButton::Fields        (TObject*            obj)
  222. {
  223.     obj->DoToField ("TPictButton", NULL, bClass);
  224.     inherited::Fields (obj);
  225. } /* Fields */
  226.  
  227. //-------------------------------------------------------
  228. // TPictCheckBox (TCtlMgr)    Picture check box
  229. //-------------------------------------------------------
  230.  
  231. #pragma segment AOpen
  232. /*----------*/
  233. pascal void TPictCheckBox::IPictCheckBox    (TView                *itsSuperView,
  234.                                              const VPoint&        itsLocation, 
  235.                                              const VPoint&        itsSize,
  236.                                              SizeDeterminer        itsHSizeDet, 
  237.                                              SizeDeterminer        itsVSizeDet,
  238.                                              const Str255&        itsPicts,
  239.                                              Boolean            isTurnedOn)
  240.     
  241. {
  242.     ICtlMgr (itsSuperView, itsLocation, itsSize, 
  243.                 itsHSizeDet, itsVSizeDet, itsPicts, 
  244.                 0, 0, 1, kPictCheckProcID);
  245.     SetState (isTurnedOn, kDontRedraw);
  246.     fDefChoice = mCheckBoxHit;
  247. } /* IPictCheckBox */
  248.  
  249. #pragma segment AInit
  250. /*----------*/
  251. pascal void TPictCheckBox::IRes     (TDocument            *itsDocument,
  252.                                      TView                *itsSuperView,
  253.                                      Ptr&                itsParams)                
  254. {
  255.     VRect                itsArea;
  256.     PictControlTPtr        ptPtr;
  257.  
  258.     inherited::IRes (itsDocument, itsSuperView, itsParams);
  259.  
  260.     fDefChoice = mCheckBoxHit;
  261.     ptPtr = (PictControlTPtr) itsParams;
  262.     ControlArea (itsArea);
  263.     CreateCMgrControl (itsArea, ptPtr->itsPictureIDs, 
  264.                             0, 0, 1, kPictCheckProcID); 
  265.  
  266.     OffsetPtrWStr (itsParams, sizeof (PictControlTemplate));
  267. } /* IRes */
  268.  
  269. #pragma segment WriteRes
  270. /*----------*/
  271. pascal void TPictCheckBox::WRes        (ViewRsrcHandle        theResource,
  272.                                      Ptr&                itsParams)                 
  273. {
  274.     Str255                theLabel;
  275.     PictControlTPtr        ptPtr;
  276.  
  277.     inherited::WRes (theResource, itsParams);    
  278.     
  279.     GetText (theLabel);
  280.     ptPtr = (PictControlTPtr) (ExpandPtrWStr ((Handle)theResource, itsParams, 
  281.                                     sizeof (PictControlTemplate), theLabel [0]));
  282.     CopyStr255 (theLabel, PRStr (ptPtr->itsPictureIDs));
  283. } /* WRes */
  284.  
  285. #pragma segment WriteRes
  286. /*----------*/
  287. pascal void TPictCheckBox::WriteRes        (ViewRsrcHandle        theResource,
  288.                                          Ptr&                itsParams)                 
  289. {
  290.     gWResSignature = kStdPictCheckBox; 
  291.     gWResType = "TPictCheckBox";
  292.     WRes (theResource, itsParams);
  293. } /* WriteRes */
  294.  
  295. #pragma segment ARes
  296. /*----------*/
  297. pascal void TPictCheckBox::DoEvent    (EvtNumber            eventNumber,
  298.                                      TEvtHandler*        source,
  299.                                      TEvent*            event)            
  300. {
  301.     if (eventNumber == mCheckBoxHit) {
  302.         Toggle (kRedraw);
  303.     }
  304.     inherited::DoEvent (eventNumber, source, event);
  305. } /* DoEvent */
  306.  
  307. #pragma segment ARes
  308. /*----------*/
  309. pascal Boolean  TPictCheckBox::IsOn    (void)
  310. {
  311.     if (GetLongVal () != 0) {
  312.         return (TRUE);
  313.     } else {
  314.         return (FALSE);
  315.     }
  316. } /* IsOn */
  317.  
  318. #pragma segment ARes
  319. /*----------*/
  320. pascal void TPictCheckBox::SetState       (Boolean            state,
  321.                                         Boolean            redraw)
  322. {
  323.     SetLongVal (state, redraw);
  324. } /* SetState */
  325.  
  326. #pragma segment ARes
  327. /*----------*/
  328. pascal void TPictCheckBox::Toggle       (Boolean            redraw)
  329. {
  330.     SetLongVal (!IsOn (), redraw);
  331. } /* Toggle */
  332.  
  333. #pragma segment ARes
  334. /*----------*/
  335. pascal void TPictCheckBox::ToggleIf       (Boolean            matchState,
  336.                                         Boolean            redraw)
  337. {
  338.     if (IsOn () == matchState) {
  339.         SetLongVal (!IsOn (), redraw);
  340.     }
  341. } /* ToggleIf */
  342.  
  343. #pragma segment AFields
  344. /*----------*/
  345. pascal void TPictCheckBox::Fields    (TObject*            obj)
  346. {
  347.     obj->DoToField ("TPictCheckBox", NULL, bClass);
  348.     inherited::Fields (obj);
  349. } /* Fields */
  350.  
  351. //-------------------------------------------------------
  352. // TPictRadio (TCtlMgr)        Picture radio button
  353. //-------------------------------------------------------
  354.  
  355. #pragma segment AOpen
  356. /*----------*/
  357. pascal void TPictRadio::IPictRadio        (TView                *itsSuperView,
  358.                                          const VPoint&        itsLocation, 
  359.                                          const VPoint&        itsSize,
  360.                                          SizeDeterminer        itsHSizeDet, 
  361.                                          SizeDeterminer        itsVSizeDet,
  362.                                          const Str255&        itsPicts,
  363.                                          Boolean            isTurnedOn)    
  364. {
  365.     ICtlMgr (itsSuperView, itsLocation, itsSize, 
  366.                 itsHSizeDet, itsVSizeDet, itsPicts, 
  367.                 0, 0, 1, kPictRadioProcID);
  368.     SetState (isTurnedOn, kDontRedraw);
  369.     fDefChoice = mRadioHit;
  370. } /* IPictRadio */
  371.  
  372. #pragma segment AInit
  373. /*----------*/
  374. pascal void TPictRadio::IRes     (TDocument            *itsDocument,
  375.                                  TView                *itsSuperView,
  376.                                  Ptr&                itsParams)                
  377. {
  378.     VRect                itsArea;
  379.     PictControlTPtr        ptPtr;
  380.  
  381.     inherited::IRes (itsDocument, itsSuperView, itsParams);
  382.  
  383.     fDefChoice = mRadioHit;
  384.     ptPtr = (PictControlTPtr) itsParams;
  385.     ControlArea (itsArea);
  386.     CreateCMgrControl (itsArea, ptPtr->itsPictureIDs, 
  387.                              0, 0, 1, kPictRadioProcID); 
  388.  
  389.     OffsetPtrWStr (itsParams, sizeof (PictControlTemplate));
  390. } /* IRes */
  391.  
  392. #pragma segment WriteRes
  393. /*----------*/
  394. pascal void TPictRadio::WRes    (ViewRsrcHandle        theResource,
  395.                                  Ptr&                itsParams)                 
  396. {
  397.     Str255                theLabel;
  398.     PictControlTPtr        ptPtr;
  399.  
  400.     inherited::WRes (theResource, itsParams);    
  401.     
  402.     GetText (theLabel);
  403.     ptPtr = (PictControlTPtr) (ExpandPtrWStr ((Handle)theResource, itsParams, 
  404.                                     sizeof (PictControlTemplate), theLabel [0]));
  405.     CopyStr255 (theLabel, PRStr (ptPtr->itsPictureIDs));
  406. } /* WRes */
  407.  
  408. #pragma segment WriteRes
  409. /*----------*/
  410. pascal void TPictRadio::WriteRes    (ViewRsrcHandle        theResource,
  411.                                      Ptr&                itsParams)                 
  412. {
  413.     gWResSignature = kStdPictRadio; 
  414.     gWResType = "TPictRadio";
  415.     WRes (theResource, itsParams);
  416. } /* WriteRes */
  417.  
  418. #pragma segment ARes
  419. /*----------*/
  420. pascal void TPictRadio::DoEvent        (EvtNumber            eventNumber,
  421.                                      TEvtHandler*        source,
  422.                                      TEvent*            event)            
  423. {
  424.     if ((eventNumber == mRadioHit) && !IsOn ()) {
  425.         Toggle (kRedraw);
  426.     }
  427.     inherited::DoEvent (eventNumber, source, event);
  428. } /* DoEvent */
  429.  
  430. #pragma segment ARes
  431. /*----------*/
  432. pascal Boolean  TPictRadio::IsOn     (void)
  433. {
  434.     if (GetLongVal () != 0) {
  435.         return (TRUE);
  436.     } else {
  437.         return (FALSE);
  438.     }
  439. } /* IsOn */
  440.  
  441. #pragma segment ARes
  442. /*----------*/
  443. pascal void TPictRadio::SetState    (Boolean            state,
  444.                                      Boolean            redraw)
  445. {
  446.     SetLongVal (state, redraw);
  447. } /* SetState */
  448.  
  449. #pragma segment ARes}
  450. /*----------*/
  451. pascal void TPictRadio::Toggle        (Boolean            redraw)
  452. {
  453.     SetLongVal (!IsOn (), redraw);
  454. } /* Toggle */
  455.  
  456. #pragma segment ARes
  457. /*----------*/
  458. pascal void TPictRadio::ToggleIf    (Boolean            matchState,
  459.                                      Boolean            redraw)
  460. {
  461.     if (IsOn () == matchState) {
  462.         SetLongVal (!IsOn (), redraw);
  463.     }
  464. } /* ToggleIf */
  465.  
  466. #pragma segment AFields
  467. /*----------*/
  468. pascal void TPictRadio::Fields         (TObject*            obj)
  469. {
  470.     obj->DoToField ("TPictRadio", NULL, bClass);
  471.     inherited::Fields (obj);
  472. } /* Fields */
  473.  
  474. //-------------------------------------------------------
  475. // TMultiPict (TCtlMgr)        Multi-picture control
  476. //-------------------------------------------------------
  477.  
  478. #pragma segment AOpen
  479. /*----------*/
  480. pascal void TMultiPict::IMultiPict        (TView                *itsSuperView,
  481.                                          const VPoint&        itsLocation, 
  482.                                          const VPoint&        itsSize,
  483.                                          SizeDeterminer        itsHSizeDet, 
  484.                                          SizeDeterminer        itsVSizeDet,
  485.                                          const Str255&        itsPicts,
  486.                                          short                curValue)    
  487. {
  488.     short        numberOfPicts;        // number of possible states for the control
  489.  
  490.     numberOfPicts = itsPicts [0] / 2;    // 2 bytes for each picture ID
  491.     ICtlMgr (itsSuperView, itsLocation, itsSize, 
  492.                 itsHSizeDet, itsVSizeDet, itsPicts, 
  493.                 1, 1, numberOfPicts, kMultiPictProcID);
  494.     SetVal (curValue, kDontRedraw);
  495.     fDefChoice = mMultiPictHit;
  496. } /* IMultiPict */
  497.  
  498. #pragma segment AInit
  499. /*----------*/
  500. pascal void TMultiPict::IRes     (TDocument            *itsDocument,
  501.                                  TView                *itsSuperView,
  502.                                  Ptr&                itsParams)                
  503. {
  504.     VRect                itsArea;
  505.     PictControlTPtr        ptPtr;
  506.     short                numberOfPicts;        // number of possible states for the control
  507.  
  508.     inherited::IRes (itsDocument, itsSuperView, itsParams);
  509.  
  510.     fDefChoice = mMultiPictHit;
  511.     ptPtr = (PictControlTPtr) itsParams;
  512.     numberOfPicts = (ptPtr->itsPictureIDs [0]) / 2;        // 2 bytes for each picture ID
  513.     ControlArea (itsArea);
  514.     CreateCMgrControl (itsArea, ptPtr->itsPictureIDs, 
  515.                              1, 1, numberOfPicts, kMultiPictProcID); 
  516.  
  517.     OffsetPtrWStr (itsParams, sizeof (PictControlTemplate));
  518. } /* IRes */
  519.  
  520. #pragma segment WriteRes
  521. /*----------*/
  522. pascal void TMultiPict::WRes    (ViewRsrcHandle        theResource,
  523.                                  Ptr&                itsParams)                 
  524. {
  525.     Str255                theLabel;
  526.     PictControlTPtr        ptPtr;
  527.  
  528.     inherited::WRes (theResource, itsParams);    
  529.     
  530.     GetText (theLabel);
  531.     ptPtr = (PictControlTPtr) (ExpandPtrWStr ((Handle)theResource, itsParams, 
  532.                                     sizeof (PictControlTemplate), theLabel [0]));
  533.     CopyStr255 (theLabel, PRStr (ptPtr->itsPictureIDs));
  534. } /* WRes */
  535.  
  536. #pragma segment WriteRes
  537. /*----------*/
  538. pascal void TMultiPict::WriteRes    (ViewRsrcHandle        theResource,
  539.                                      Ptr&                itsParams)                 
  540. {
  541.     gWResSignature = kStdMultiPict; 
  542.     gWResType = "TMultiPict";
  543.     WRes (theResource, itsParams);
  544. } /* WriteRes */
  545.  
  546. #pragma segment ARes
  547. /*----------*/
  548. pascal void TMultiPict::DoEvent        (EvtNumber            eventNumber,
  549.                                      TEvtHandler*        source,
  550.                                      TEvent*            event)            
  551. {
  552.     if (eventNumber == mMultiPictHit) {
  553.         Cycle (kRedraw);
  554.     }
  555.     inherited::DoEvent (eventNumber, source, event);
  556. } /* DoEvent */
  557.  
  558. #pragma segment ARes
  559. /*----------*/
  560. pascal void TMultiPict::Cycle    (Boolean        redraw)
  561. {
  562.     short        curVal;
  563.  
  564.     curVal = GetVal ();
  565.  
  566.     if (curVal == GetMax ()) {
  567.         curVal = GetMin ();
  568.     } else {
  569.         curVal++;
  570.     }
  571.     SetVal (curVal, redraw);
  572. } /* Cycle */
  573.  
  574. #pragma segment AFields
  575. /*----------*/
  576. pascal void TMultiPict::Fields        (TObject*            obj)
  577. {
  578.     obj->DoToField ("TMultiPict", NULL, bClass);
  579.     inherited::Fields (obj);
  580. } /* Fields */
  581.  
  582. //-------------------------------------------------------
  583. // TSlider (TCtlMgr)        Custom slider
  584. //-------------------------------------------------------
  585.  
  586. #pragma segment AOpen
  587. /*----------*/
  588. pascal void TSlider::ISlider    (TView                *itsSuperView,
  589.                                  const VPoint&        itsLocation, 
  590.                                  const VPoint&        itsSize,
  591.                                  SizeDeterminer        itsHSizeDet, 
  592.                                  SizeDeterminer        itsVSizeDet,
  593.                                  VHSelect            itsDirection,
  594.                                  const Str255&        itsPicts,
  595.                                  short                itsProcID,
  596.                                  long                itsVal,
  597.                                  long                itsMin,
  598.                                  long                itsMax)    
  599. {
  600.     ICtlMgr (itsSuperView, itsLocation, itsSize, 
  601.                 itsHSizeDet, itsVSizeDet, itsPicts, itsVal, itsMin, itsMax, itsProcID);
  602.     fDirection = itsDirection;
  603.     fDefChoice = mSliderHit;
  604. } /* ISlider */
  605.  
  606. #pragma segment AInit
  607. /*----------*/
  608. pascal void TSlider::IRes     (TDocument            *itsDocument,
  609.                              TView                *itsSuperView,
  610.                              Ptr&                itsParams)                
  611. {
  612.     VRect            itsArea;
  613.     SliderTPtr        stPtr;
  614.  
  615.     inherited::IRes (itsDocument, itsSuperView, itsParams);
  616.     
  617.     fDefChoice = mSliderHit;
  618.     stPtr = (SliderTPtr) itsParams;
  619.     ControlArea (itsArea);
  620.     CreateCMgrControl (itsArea, stPtr->itsPictureIDs,
  621.                             0, 0, 10, kSliderProcID + stPtr->itsVariantCode);
  622.  
  623.     if ((itsArea.bottom - itsArea.top)
  624.     >=  (itsArea.right - itsArea.left)) {
  625.         fDirection = vSel;
  626.     } else {
  627.         fDirection = hSel;
  628.     }
  629.  
  630.     OffsetPtrWStr (itsParams, sizeof (SliderTemplate));
  631. } /* IRes */
  632.  
  633. #pragma segment WriteRes
  634. /*----------*/
  635. pascal void TSlider::WRes        (ViewRsrcHandle        theResource,
  636.                                  Ptr&                itsParams)                
  637. {
  638.     Str255            theLabel;
  639.     SliderTPtr        stPtr;
  640.  
  641.     inherited::WRes (theResource, itsParams);    
  642.     
  643.     GetText (theLabel);
  644.     stPtr = (SliderTPtr) (ExpandPtrWStr ((Handle)theResource, itsParams, 
  645.                                     sizeof (SliderTemplate), theLabel [0]));
  646.     stPtr->itsVariantCode = 0;    // should be control's variant code
  647.     CopyStr255 (theLabel, PRStr (stPtr->itsPictureIDs));
  648. } /* WRes */
  649.  
  650. #pragma segment WriteRes
  651. /*----------*/
  652. pascal void TSlider::WriteRes    (ViewRsrcHandle        theResource,
  653.                                  Ptr&                itsParams)                 
  654. {
  655.     gWResSignature = kStdSlider; 
  656.     gWResType = "TSlider";
  657.     WRes (theResource, itsParams);
  658. } /* WriteRes */
  659.  
  660. #pragma segment ARes
  661. /*----------*/
  662. pascal void TSlider::DeltaValue          (VCoordinate        delta)
  663. {
  664.     if (delta != 0) {
  665.         if (delta > 0) {
  666.             delta = Min (delta, fLongMax - fLongVal);
  667.         } else {
  668.             delta = Max (delta, fLongMin - fLongVal);
  669.         }
  670.  
  671.         SetLongVal (fLongVal + delta, TRUE);
  672.     }
  673. } /* DeltaValue */
  674.  
  675. #pragma segment ASelCommand
  676. /*----------*/
  677. pascal void TSlider::DoMouseCommand     (VPoint&            theMouse,
  678.                                          TToolboxEvent*        event,
  679.                                          Point                hysteresis)
  680. {
  681.     short            partCode;
  682.     VCoordinate        oldLongValue;
  683.     VCoordinate        newLongValue;
  684.  
  685. #if qDebug
  686.         AssumeFocused ();
  687. #endif
  688.     
  689.     oldLongValue = fLongVal;
  690.     partCode = TestControl (fCMgrControl, theMouse);
  691.     
  692.     switch (partCode) {
  693.         case inUpButton:
  694.         case inDownButton: 
  695.         case inPageUp:
  696.         case inPageDown:    
  697.                 partCode = TrackControl (fCMgrControl, theMouse, (ProcPtr)&ActionProcForTSlider);
  698.                 if (fLongVal != oldLongValue) {
  699.                     HandleEvent (fDefChoice, this, NULL);
  700.                 }
  701.             break;
  702.         case inThumb:
  703.                 if (TrackControl (fCMgrControl, theMouse, NULL) == inThumb) {
  704.                     if (GetVal () == GetMax ()) {
  705.                         newLongValue = fLongMax;
  706.                     } else {
  707.                         newLongValue = ((long) GetVal () << fBitsToShift);
  708.                     }
  709.                     SetLongVal(newLongValue, kRedraw);
  710.                 }
  711.  
  712.                 if (fLongVal != oldLongValue) {
  713.                     HandleEvent (fDefChoice, this, NULL);
  714.                 }
  715.             break;
  716.         default:
  717.             break;
  718.     } /* switch */
  719.     
  720. } /* DoMouseCommand */
  721.  
  722. #pragma segment ARes
  723. /*----------*/
  724. pascal void TSlider::TrackSlider    (short        /* partCode */)
  725. {
  726.     DeltaValue (1);        // only one part code
  727. } /* TrackSlider */
  728.  
  729. #pragma segment ASelCommand
  730. /*----------*/
  731. /* this is based on TScrollBar.ActionProc.  I'm not completely sure it's right */
  732. pascal void TSlider::ActionProc            (short        partCode)
  733. {
  734.     if (partCode != 0) {
  735.         TrackSlider (partCode);        // bounds checking?
  736.     }
  737.     Update ();
  738.     if (Focus ()) {
  739.     }
  740. } /* ActionProc */
  741.  
  742. #pragma segment AFields
  743. /*----------*/
  744. pascal void TSlider::Fields        (TObject*            obj)
  745. {
  746.     obj->DoToField ("TSlider", NULL, bClass);
  747.     obj->DoToField ("fDirection", (Ptr)&fDirection, bVHSelect);
  748.     inherited::Fields (obj);
  749. } /* Fields */
  750.  
  751. //-------------------------------------------------------
  752. // TCustom (TCtlMgr)        Other custom control
  753. //-------------------------------------------------------
  754.  
  755. struct CntlTemplate {
  756.     Rect         boundsRect;
  757.     short        value;
  758.     Boolean        visible;
  759.     Boolean        filler1;
  760.     short        max;
  761.     short        min;
  762.     short        procID;
  763.     long        refCon;
  764.     Str255        title;
  765. }; 
  766. typedef CntlTemplate *ControlTPtr, **ControlTHndl;
  767.  
  768. #pragma segment AOpen
  769. /*----------*/
  770. pascal void TCustom::ICustom     (TView                *itsSuperView,
  771.                                  const VPoint&        itsLocation, 
  772.                                  const VPoint&        itsSize,
  773.                                  SizeDeterminer        itsHSizeDet, 
  774.                                  SizeDeterminer        itsVSizeDet,
  775.                                  short                itsCntlID)    
  776. {
  777.     ControlTHndl    itsCNTL;
  778.     short            min;
  779.     short            max;
  780.  
  781.     fCntlID = itsCntlID;
  782.     itsCNTL = (ControlTHndl) Get1Resource ('CNTL', itsCntlID);
  783.     LoadResource ((Handle) itsCNTL);
  784.     HLock ((Handle) itsCNTL);
  785.     min    = (**itsCNTL).min;
  786.     max = (**itsCNTL).max;
  787.     ICtlMgr (itsSuperView, itsLocation, itsSize, 
  788.                 itsHSizeDet, itsVSizeDet, (**itsCNTL).title, 
  789.                 min, min, max, (**itsCNTL).procID);
  790.     ReleaseResource ((Handle) itsCNTL);
  791.     fDefChoice = mCustomHit;
  792. } /* ICustom */
  793.  
  794. #pragma segment AInit
  795. /*----------*/
  796. pascal void TCustom::IRes    (TDocument            *itsDocument,
  797.                              TView                *itsSuperView,
  798.                              Ptr&                itsParams)
  799. {
  800.     VRect                itsArea;
  801.     CustomControlTPtr    ctPtr;
  802.     ControlTHndl        itsCNTL;
  803.     short                min;
  804.     short                max;
  805.  
  806.     inherited::IRes (itsDocument, itsSuperView, itsParams);
  807.  
  808.     fDefChoice = mCustomHit;
  809.     ctPtr = (CustomControlTPtr) itsParams;
  810.     fCntlID = ctPtr->itsCntlID;
  811.     itsCNTL = (ControlTHndl) Get1Resource ('CNTL', ctPtr->itsCntlID);
  812.     LoadResource ((Handle) itsCNTL);
  813.     HLock ((Handle) itsCNTL);
  814.     min    = (**itsCNTL).min;
  815.     max = (**itsCNTL).max;
  816.     ControlArea (itsArea);
  817.     CreateCMgrControl (itsArea, (**itsCNTL).title, min, min, max, (**itsCNTL).procID); 
  818.     ReleaseResource ((Handle) itsCNTL);
  819.  
  820.     OffsetPtr (itsParams, sizeof (CustomControlTemplate));
  821. } /* IRes */
  822.  
  823. #pragma segment WriteRes
  824. /*----------*/
  825. pascal void TCustom::WRes    (ViewRsrcHandle        theResource,
  826.                              Ptr&                itsParams) 
  827. {
  828.     Str255                theLabel;
  829.     CustomControlTPtr    ctPtr;
  830.  
  831.     inherited::WRes (theResource, itsParams);    
  832.     
  833.     ctPtr = (CustomControlTPtr) (ExpandPtr ((Handle)theResource, itsParams, 
  834.                                     sizeof (CustomControlTemplate)) );
  835.     ctPtr->itsCntlID = fCntlID;
  836. } /* WRes */
  837.  
  838. #pragma segment WriteRes
  839. /*----------*/
  840. pascal void TCustom::WriteRes    (ViewRsrcHandle        theResource,
  841.                                  Ptr&                itsParams)
  842. {
  843.     gWResSignature = kStdCustom; 
  844.     gWResType = "TCustom";
  845.     WRes (theResource, itsParams);
  846. } /* WriteRes */
  847.  
  848. #pragma segment AFields
  849. /*----------*/
  850. pascal void TCustom::Fields        (TObject*            obj)
  851. {
  852.     obj->DoToField ("TCustom", NULL, bClass);
  853.     obj->DoToField ("fCntlID", (Ptr)&fCntlID, bInteger);
  854.     inherited::Fields (obj);
  855. } /* Fields */
  856.  
  857. /* UAMLibrary.cp */
  858.